package org.example.erp.controller;

import org.example.erp.domain.WarehouseLocation;
import org.example.erp.service.impl.WarehouseLocationServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class WarehouseLocationController {
    @Autowired
    WarehouseLocationServiceImpl warehouseLocationService;

    @GetMapping("/warehouseLocation/find")
    public DataResult findwarehouseLocation(@RequestParam(value = "currentPage", defaultValue = "1") Integer currentPage,
                                        @RequestParam(value = "pageSize", defaultValue = "5") Integer pageSize,
                                        @RequestParam Integer warehouseAreaId,
                                        @RequestParam (required = false) String warehouseLocationCode,
                                        @RequestParam (required = false) String warehouseLocationName
    ){
        return DataResult.success(warehouseLocationService.findLocation(currentPage,pageSize,warehouseAreaId,warehouseLocationCode,warehouseLocationName));
    }

    @PostMapping("/warehouseLocation/insert")
    public DataResult insertwarehouseLocation(@RequestBody WarehouseLocation warehouseLocation){
        return DataResult.success(warehouseLocationService.save(warehouseLocation));
    }


    @PutMapping("/warehouseLocation/update")
    public DataResult updatewarehouseLocation(@RequestBody WarehouseLocation warehouseLocation){
        return DataResult.success(warehouseLocationService.updateById(warehouseLocation));
    }

    @DeleteMapping("/warehouseLocation/detele")
    public DataResult datelewarehouseLocation(@RequestBody List<Integer> logIds){
        return DataResult.success(warehouseLocationService.removeByIds(logIds));
    }
}
